package com.qianyu.project.service.handler;

import com.alibaba.fastjson.JSON;
import com.qianyu.project.core.annotation.FlowHandler;
import com.qianyu.project.core.bean.FormAudit;
import com.qianyu.project.core.context.handler.FlowFinishedHandler;
import com.qianyu.project.entity.SubTenderPlan;
import com.qianyu.project.entity.WorkLog;
import com.qianyu.project.service.IWorkLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author nyx
 * @date create in 2021/2/4
 */
@Component
@FlowHandler("work_log")
public class WorkLogHandler implements FlowFinishedHandler {

    @Autowired
    private IWorkLogService workLogService;

    @Override
    public void postAllowHandle(String jsonForm, FormAudit formAudit) {
        this.commonUpdate(jsonForm, formAudit, 3);
    }

    @Override
    public void postRefuseHandle(String jsonForm, FormAudit formAudit) {
        this.commonUpdate(jsonForm, formAudit, 2);
    }

    private void commonUpdate(String jsonForm, FormAudit formAudit, Integer approveStatus) {
        WorkLog workLog = JSON.parseObject(jsonForm, WorkLog.class);
        workLog.setApproveStatus(approveStatus.toString());
        workLogService.updateById(workLog);
    }

}
